#include "ranges.h"

#include <cstdint>
#include <cstdio>
#include <vector>

void Ranges::AddRange(uint32_t start, uint32_t end)
{
    if (ranges.empty() || ranges.back().end != start) {
        ranges.push_back({start, end});
    } else {
        ranges.back().end = end;
    }
}

bool Ranges::Has(uint32_t codepoint)
{
    for (auto range : ranges) {
        if (codepoint > range.end) {
            continue;
        }

        if (codepoint >= range.start) {
            return true;
        }
        break;
    }
    return false;
}

void Ranges::Dump(const char *prefix)
{
    for (auto range : ranges) {
        printf("%s0x%04X ~ 0x%04X\n", prefix, range.start, range.end);
    }
}
